
package cn.com.pxto.web.action;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class LogoutAction extends Action {
	private Log log  = LogFactory.getLog(LogoutAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.info("entering LogoutAction ...");
		HttpSession session = request.getSession();
		Integer type=(Integer) session.getAttribute("type");
		if (session.getAttribute("logonInfo")!=null){			
			//remove actived loginfo from Session 
			session.removeAttribute("LogedSessionListener");
			//remove all session elements from session;
			Enumeration element = session.getAttributeNames(); 
			while (element.hasMoreElements()){
				String elementName = (String)element.nextElement();
				session.removeAttribute(elementName);
			}
		}else{
			log.info("session overtime ...");
			return mapping.findForward("userLogout");
		}
		if(type.intValue()==1 ){
			log.info("manager logout ...");
			return mapping.findForward("ManagerLogout");
		}else
			log.info("user logout ...");
			return mapping.findForward("userLogout");

	}
}
